package client

import (
	"github.com/akirakazu/go-simplejson"
)

func (c *Client) onRequest(m *Pack) {
	c.delegate.onRequest(m)
}

func (c *Client) request(msg *json.Json, fn func(string, *json.Json, *json.Json)) string {
	if !msg.Has("to") {
		c.delegate.onError("to missing")
		return ""
	}

	m := NewPack("request", msg)
	queue := false
	if msg.Has("queue") && msg.GetBool("queue") == true {
		queue = true
	}
	c.addRequest(m.Id, m, fn, queue)
	c.sendPack(m, queue)
}
